package com.invite.me.ui.yaoyue;

import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.resource.bitmap.RoundedCorners;
import com.bumptech.glide.request.RequestOptions;
import com.invite.me.R;
import com.invite.me.base.BaseActivity;
import com.invite.me.beans.adpater.MyInfoAdpater;
import com.invite.me.beans.presenter.MyInfoPresenter;
import com.invite.me.beans.res.BlindDataParticularsBean;
import com.invite.me.util.SspPrefUtils;
import com.invite.me.wlqq.Constants;
import com.invite.me.wlqq.Contract;
import com.library.flowlayout.FlowLayoutManager;
import com.library.flowlayout.SpaceItemDecoration;

import java.util.ArrayList;
import java.util.List;

public class MyInfoActivity extends BaseActivity implements View.OnClickListener,Contract.BaseView  {
    MyInfoPresenter myInfoPresenter;
    MyInfoAdpater myInfoAdpater;
    private ImageView touxiang;
    private TextView name;
    private ImageView tubiao;
    private TextView pricexs;
    //private List<MyinfoBiaoQianBean> myTagList=new ArrayList<>();
    List<BlindDataParticularsBean.DataBean.MyTagListBean> myTagList = new ArrayList<>();

    @Override
    protected void initView() {
        myInfoPresenter=new MyInfoPresenter(this);

        ImageView image_fanhui = findViewById(R.id.image_fanhui);
        image_fanhui.setOnClickListener(this);
        ImageView shezhi = findViewById(R.id.shezhi);
        touxiang = findViewById(R.id.touxiang);
        name = findViewById(R.id.name);
        tubiao = findViewById(R.id.tubiao);
        pricexs = findViewById(R.id.pricexs);
        RecyclerView recyclerviwemyzl = findViewById(R.id.recyclerviwemyzl);
        FlowLayoutManager flowLayoutManager = new FlowLayoutManager();
        recyclerviwemyzl.addItemDecoration(new SpaceItemDecoration(dp2px(5)));
        recyclerviwemyzl.setLayoutManager(flowLayoutManager);
        myInfoAdpater=new MyInfoAdpater(R.layout.zuijintext_list,myTagList);
        recyclerviwemyzl.setAdapter(myInfoAdpater);

        shezhi.setOnClickListener(this);


    }

    @Override
    protected void onResume() {
        super.onResume();
        myInfoPresenter.myxinxi();
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.shezhi:
                Intent sz=new Intent(MyInfoActivity.this, MyInfoEditActivity.class);

                startActivity(sz);
                if(myTagList.size()>0){
                    myTagList.clear();
                }


                break;
            case R.id.image_fanhui:
                finish();
                break;

        }


    }
    @Override
    protected int getActivityLayoutId() {
        return R.layout.activity_mydata;
    }
    private int dp2px(float value) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, value, getResources().getDisplayMetrics());
    }

    @Override
    protected void loadData() {

    }


    @Override
    public void setPresenter(Contract.BasePresenter basePresenter) {
        if (myInfoPresenter instanceof Contract.BasePresenter) {
            this.myInfoPresenter = (MyInfoPresenter) basePresenter;
        }
    }

    @Override
    public void onDataSucess(Object o) {
        if(o instanceof BlindDataParticularsBean){
            BlindDataParticularsBean blindDataParticularsBean= (BlindDataParticularsBean) o;
            if(blindDataParticularsBean.getCode()==1000){
                if(blindDataParticularsBean.getData()!=null){
                    String nickname = blindDataParticularsBean.getData().getNickname();
                    String discribe = blindDataParticularsBean.getData().getDiscribe();//头像
                    if(TextUtils.isEmpty(nickname)&&TextUtils.isEmpty(discribe)){
//                        Intent sz=new Intent(MyInfoActivity.this, MyInfoEditActivity.class);
//                        startActivity(sz);

                    }else{

                        int sex = blindDataParticularsBean.getData().getSex();
                        //  String intention = blindDataParticularsBean.getData().getIntention();
                        double price = blindDataParticularsBean.getData().getPrice();
                        SspPrefUtils.setString(Constants.NAKNAME,nickname);
                        name.setText(nickname);
                        pricexs.setText(price+"");
                        Glide.with(this)
                                .load(discribe)
                                .apply(RequestOptions.bitmapTransform(new RoundedCorners(20)))//圆角半径
                                .into(touxiang);
                        if(sex==1){
                            tubiao.setImageResource(R.mipmap.nanbiaoshi);
                        }else if(sex==2){
                            tubiao.setImageResource(R.mipmap.nxbs);
                        }

                        myTagList.addAll(blindDataParticularsBean.getData().getMyTagList());

                        myInfoAdpater.notifyDataSetChanged();
                    }





//                    for (int i=0;i<myTagList.size();i++){
//                        String title = myTagList.get(i).getTitle();
//                        list.add()
//
//                    }


                }


            }



        }

    }

    @Override
    public void onDataFaile(Object o) {

    }

    @Override
    public void onComplete() {

    }
}
